package com.wanhugou.payment.job;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alipay.api.AlipayApiException;
import com.wanhugou.payment.config.SystemConfig;
import com.wanhugou.payment.dao.PayLogDao;
import com.wanhugou.payment.domain.PayLog;
import com.wanhugou.payment.util.AliPayUtils;

@Service
public class AliOrderCheckTask {
	
	@Autowired
	private PayLogDao dao;
	
	@Autowired
	private SystemConfig conf;
	
	@Autowired
	private AliPayUtils aliUtil;
	
	public void execute() throws AlipayApiException{
		//查询所有支付宝未完成订单
		List<PayLog> pays = dao.selectUnfinished("a");
		if(pays != null && !pays.isEmpty()){
			for(PayLog p : pays){
				String query = aliUtil.query(p.getOut_trade_no());
				if(conf.getRes_success().equals(query)){
					dao.updateStatus(p.getOut_trade_no());
				}
			}
		}
	}
}
